package xml;

import java.util.Map;
import javax.xml.stream.*;
import javax.xml.stream.events.*;

public class XMLWriter {
	public String filenameTimeStamp;
	

	public XMLWriter(String filenameTimeStamp) {
		this.filenameTimeStamp = filenameTimeStamp;
	}


	@SuppressWarnings("restriction")
	public void createNode(XMLEventWriter eventWriter, String name, String value, Map<String, String> attributes) throws XMLStreamException {
		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		XMLEvent tab = eventFactory.createDTD("\t");
		
		eventWriter.add(tab);
		// Create Start node
		StartElement sElement = eventFactory.createStartElement("", "", name);
		eventWriter.add(sElement);
		
		if (attributes != null)
			for (String key : attributes.keySet()) { 
				Attribute attribute = eventFactory.createAttribute(key, attributes.get(key));
				eventWriter.add(attribute);
			}
		
		
		// Create Content
		Characters characters = eventFactory.createCharacters(value);
		eventWriter.add(characters);
				
		//Create End node
		EndElement eElement = eventFactory.createEndElement("", "", name);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}

}
